#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <random>
#include <cmath>

using namespace std;





class crew{
	public:
		// int year;
		// void add_people();

		int id;
		int primary_specialty;
		int secondary_specialty;
		int rank;
		int orders;
		int proficiency;
};

class specialist : public crew{
	
};



int assign_proficiency(){


    random_device rd{};
    mt19937 gen{rd()};
 
    // values near the mean are the most likely
    // standard deviation affects the dispersion of generated values from the mean
    normal_distribution<> d{100,15};
 
    map<int, int> hist{};
    // for(int n=0; n<10; ++n) {
        // ++hist[std::round(d(gen))];
        // cout<<round(d(gen))<<endl;
    // }

    return round(d(gen));


}
// void crew :: add_people(){
// 	crew people[10];

// }

// }
int make_specialist_people(specialist people[], int c, int n, int s, int ss, int r){
	int ii;

	for(int i=c; i<c+n; i++){
		people[i].id = i;
		people[i].primary_specialty = s;
		people[i].secondary_specialty = ss;
		people[i].rank = r;
		people[i].orders = 0;
		people[i].proficiency = assign_proficiency();

		// cout<<people[i].id<<endl;

		ii=i;
	}
	// cout<<"jjjjjjjjjjjjjjjjjj"<<endl;
	
	return ii+1;
}



int make_people(crew people[], int c, int n, int s, int ss, int r){
	int ii;

	for(int i=c; i<c+n; i++){
		people[i].id = i;
		people[i].primary_specialty = s;
		people[i].secondary_specialty = ss;
		people[i].rank = r;
		people[i].orders = 0;
		people[i].proficiency = assign_proficiency();

		// cout<<people[i].id<<endl;

		ii=i;
	}
	// cout<<"jjjjjjjjjjjjjjjjjj"<<endl;
	
	return ii+1;
}

// void find_onOrder(crew people[], crew onOrder[], int a1){
// 	for(int i=0; i<1100; i++){
// 		if(people[i].primary_specialty==a1){
// 			onOrder[i]  = people[i];
// 			// break;
// 			return;

// 		}
// 		// return;

// 	}
// }





void promptt(crew people[], crew onOrder[], int aa, int a1, int oa){
	string specialty_data[] = {"Pilots/Navigation","Engineering","Systems","Logistics","Security","Medical","Legal","Combat"};

	

	cout << "1. Enter mission" << endl;
	cout << "2. Display away teams" << endl;
	cout << "3. Reset all away teams" << endl;
	cout << "4. Exit" << endl;
	cin >> aa;
	// cin.ignore();
	if(aa == 1){
		cout << "Enter mission eg. 2 3 4 5" << endl;
		cin.ignore();


		string str;
	    getline(cin, str);

	    int buf;                 // Have a buffer string
	    stringstream ss(str);       // Insert the string into a stream

	    vector<int> tokens; // Create vector to hold our words

	    while (ss >> buf)
	    {
	        tokens.push_back(buf);
	    	// cout<< buf<<endl;
	    	for(int i=0; i<1100; i++){
				if(people[i].primary_specialty == buf && people[i].orders == 0){
					people[i].orders = 1;
					onOrder[oa]  = people[i];
					oa++;








					// break;
					// cin.ignore();
					// return;
					// cin.ignore();
					// promptt(people,onOrder);
					break;
				}
				// return;

			}

		}
		cout<<"\n"<<endl;
		promptt(people, onOrder, aa, a1, oa);
		// while(cin>>a1){
		// 	// cout << a1;
		// 	for(int i=0; i<1100; i++){
		// 		if(people[i].primary_specialty==a1){
		// 			onOrder[oa]  = people[i];
		// 			oa++;
		// 			// break;
		// 			// cin.ignore();
		// 			// return;
		// 			// cin.ignore();
		// 			// promptt(people,onOrder);
		// 			break;
		// 		}
		// 		// return;

		// 	}
		// 	// promptt(people, onOrder, aa, a1, oa);

		// 	// cin.ignore();
		// 	// cin.clear();
		// }
// cout<<4<<endl;
	


	}else if(aa == 2){
		
		if(oa==0){
			cout<<"\n"<<endl;
			cout << "No Away Team" << endl;
			// cout<<"\n"<<endl;
		}else{
			cout<<"\n"<<endl;
			cout << "Away Teams;" << endl;
			cout<<"-------------------------------"<<endl;
		}

		for(int i=0; i<oa; i++){
			// cout<<"-------------------------------"<<endl;
			
			cout<<specialty_data[onOrder[i].primary_specialty]<<endl;
			cout<<"id:\t\t"<< onOrder[i].id<<endl;
			cout<<"rank:\t\t"<< onOrder[i].rank<<endl;
			cout<<"proficiency:\t"<< onOrder[i].proficiency<<endl;

			cout<<"-------------------------------"<<endl;
		}
		cout<<"\n"<<endl;
		promptt(people, onOrder, aa, a1, oa);

	}else if(aa == 3){
		cout<<"\n"<<endl;
		promptt(people, onOrder, aa, a1, 0);
		// cout <<(sizeof(people)/sizeof(*people))<<endl;
	}else if(aa == 4){
	}


}


int main(){
	int c = 0;
	int cs = 0;
	int number_people;
	int number_specialist_people;

	// crew obj1;
	// obj1.year = 1990;

	// cout << obj1.year << endl;
	crew people[1100];
	crew onOrder[1100];
	// // int arr1[10];
	specialist peeps[1100];

	// c=make_people(people,c,1,5,15);
	// c=make_people(people,c,2,5,14);
	// c=make_people(people,c,4,5,13);
	// c=make_people(people,c,8,5,12);
	// c=make_people(people,c,16,5,11);
	// c=make_people(people,c,32,5,10);

	for(int i=1; i<9; i++){
		cs=make_specialist_people(peeps,cs,1,i,0,9);
		cs=make_specialist_people(peeps,cs,2,i,0,8);
		cs=make_specialist_people(peeps,cs,2,i,0,7);
		cs=make_specialist_people(peeps,cs,4,i,0,6);
		cs=make_specialist_people(peeps,cs,4,i,0,5);
		cs=make_specialist_people(peeps,cs,8,i,0,4);
		cs=make_specialist_people(peeps,cs,16,i,0,3);
		cs=make_specialist_people(peeps,cs,32,i,0,2);
		cs=make_specialist_people(peeps,cs,64,i,0,1);
		number_specialist_people = cs;
	}


	for(int i=1; i<9; i++){
		c=make_people(people,c,1,i,0,9);
		c=make_people(people,c,2,i,0,8);
		c=make_people(people,c,2,i,0,7);
		c=make_people(people,c,4,i,0,6);
		c=make_people(people,c,4,i,0,5);
		c=make_people(people,c,8,i,0,4);
		c=make_people(people,c,16,i,0,3);
		c=make_people(people,c,32,i,0,2);
		c=make_people(people,c,64,i,0,1);
		number_people = c;
	}
	int aa, a1, oa=0;
	promptt(people, onOrder, aa, a1, oa);

	// for(int i=0; i<600; i++){
	// 	// if(onOrder)
	// }
}